package br.edu.unifei.cct720.trabalho07.principal.gui;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.border.TitledBorder;

import br.edu.unifei.cct720.trabalho07.componentes.gui.JButtonLimpar;
import br.edu.unifei.cct720.trabalho07.componentes.gui.JButtonSair;
import br.edu.unifei.cct720.trabalho07.componentes.gui.JButtonSobre;
import br.edu.unifei.cct720.trabalho07.gui.painel.PainelCurva;
import br.edu.unifei.cct720.trabalho07.gui.painel.PainelMenuAcoes;
import br.edu.unifei.cct720.trabalho07.gui.painel.PainelMenuCurva;
import br.edu.unifei.cct720.trabalho07.gui.painel.PainelMenuFuncoes;
import br.edu.unifei.cct720.trabalho07.gui.painel.PainelPontoControle;
import br.edu.unifei.cct720.trabalho07.principal.controlador.ControladorPrincipal;

public class JanelaPrincipal extends javax.swing.JFrame {

	// Declaracao das variaveis de instancia
	private ControladorPrincipal med;

	/**
	 * Construtor
	 * 
	 * @param String title
	 */
	public JanelaPrincipal(String title) {
		super(title);
		this.med = new ControladorPrincipal(this);
		this.initComponents();
		this.med.registraEventos();
		this.inicializarAcoesDoMenu();
	}

	/**
	 * Metodo responsavel pela inicializacao e
	 * disposicao dos componentes da GUI
	 * 
	 * @return void
	 */
	public void initComponents() {

		java.awt.GridBagConstraints gridBagConstraints;

		panelMenuFuncoes = new PainelMenuFuncoes("Menu de Funcoes", this.med);
		panelCurva = new PainelCurva("");
		panelPontoControle = new PainelPontoControle("Pontos de Controle");
		panelMenuCurvas = new PainelMenuCurva("Tipos de curva");
		panelMenuAcoes = new PainelMenuAcoes("Acoes");
		
		// Definindo o content que sera utilizado na janela
		getContentPane().setLayout(new java.awt.GridBagLayout());
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenuCurvas, gridBagConstraints);
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenuAcoes, gridBagConstraints);
			
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.weighty = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelCurva, gridBagConstraints);
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.ipadx = 200;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
		gridBagConstraints.gridheight = 4;
		gridBagConstraints.weighty = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelPontoControle, gridBagConstraints);
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenuFuncoes, gridBagConstraints);
		
		this.setExtendedState(MAXIMIZED_BOTH);	
		this.setVisible(true);
		this.setResizable(false);
	}

	// Declaracao dos componentes da GUI
	private PainelMenuCurva panelMenuCurvas;
	private PainelMenuAcoes panelMenuAcoes;
	private PainelMenuFuncoes panelMenuFuncoes;
	private PainelPontoControle panelPontoControle;
	private PainelCurva panelCurva;
	
	/**
	 * 
	 */
	public void inicializarAcoesDoMenu() {
		this.getPanelMenuAcoes().getRadioButtonAddPoints().setSelected(true);
		this.getPanelMenuCurvas().getCheckBoxBezier().setSelected(true);
		this.getPanelMenuCurvas().getCheckBoxExibirPoligono().setSelected(false);
		this.getPanelMenuCurvas().getScrollBar().setValue(15);
		this.getPanelPontoControle().getTxtPontosControle().setText("");
		this.med.setPrecisao(this.getPanelMenuCurvas().getScrollBar().getValue());
	}
	
	// Metodos getters e setters 	
	public PainelCurva getPanelCurva() {
		return panelCurva;
	}

	public PainelMenuCurva getPanelMenuCurvas() {
		return panelMenuCurvas;
	}

	public PainelPontoControle getPanelPontoControle() {
		return panelPontoControle;
	}

	public PainelMenuAcoes getPanelMenuAcoes() {
		return panelMenuAcoes;
	}

	public PainelMenuFuncoes getPanelMenuFuncoes() {
		return panelMenuFuncoes;
	}
}
